package com.example.simin_manage.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.simin_manage.admim.dto.Response;
import com.example.simin_manage.dto.PerformanceLogVO;
import com.example.simin_manage.entity.PerformanceLog;
import com.example.simin_manage.mapper.PerformanceLogMapper;
import com.example.simin_manage.service.PerformanceLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description:
 * @author: panpan
 * @time: 2025/9/21
 */
@RestController
@RequestMapping("/api/logs")
public class PerformanceLogController {

    @Autowired
    private PerformanceLogService logService;

    @GetMapping("/list")
    public Response listLogs(@RequestParam Long leaderId,
                             @RequestParam(required = false) Long userId,
                             @RequestParam(required = false) String startDate,
                             @RequestParam(required = false) String endDate,
                             @RequestParam(defaultValue = "1") int pageNum,
                             @RequestParam(defaultValue = "10") int pageSize) {
        IPage<PerformanceLogVO> page = logService.listLogs(leaderId, userId, startDate, endDate, pageNum, pageSize);
        return new Response(200, "查询成功", page);
    }

    /**
     * 删除所有日志
     */
    @DeleteMapping("/deleteAll")
    public Response deleteAllLogs() {
        logService.deleteAll();
        return new Response(200, "所有日志已清空", null);
    }

}
